package com.greyu.ysj.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.greyu.ysj.config.ResultStatus;
import com.greyu.ysj.entity.CbtBallot;
import com.greyu.ysj.entity.CbtDraw;
import com.greyu.ysj.mapper.CbtBallotMapper;
import com.greyu.ysj.mapper.CbtDrawMapper;
import com.greyu.ysj.model.ResultModel;
import com.greyu.ysj.service.CbtBallotService;
import com.greyu.ysj.service.CbtDrawService;

@Service
@Transactional
public class CbtBallotServiceImpl implements CbtBallotService {
	@Autowired
	private CbtBallotMapper cbtBallotMapper;


	@Override
	public ResultModel save(CbtBallot cbtBallot) {
		try {	
			if ( cbtBallot.getCoinId()==null
					||cbtBallot.getBallotDate()==null
					||cbtBallot.getCount()==null
					||cbtBallot.getUserId()==null
	        		) {
	            return ResultModel.error(ResultStatus.DATA_NOT_NULL);
	        }
			//insert
	        this.cbtBallotMapper.insert(cbtBallot);
		} catch (Exception e) {
			return ResultModel.error(ResultStatus.BALLOT_INSERT_ERROR);
		}
	        return ResultModel.ok(cbtBallot);
		}


	@Override
	public ResultModel selectCoinVotesList() {
		List coinVotesList=this.cbtBallotMapper.selectCoinVoteList();
		if(coinVotesList==null||coinVotesList.size()<1){
			
			return null;
		} 
		return ResultModel.ok(coinVotesList);
	}

}




